package com.yang.servlet;

import com.yang.pojo.Category;
import com.yang.service.CategoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/CategoryQueryServlet")
public class CategoryQueryServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        CategoryService categoryService = new CategoryService();
        int categoryId = Integer.parseInt(request.getParameter("categoryId"));
        try {
            Category category = categoryService.findCategoryByCategoryId(categoryId);
            request.setAttribute("category",category);
            request.getRequestDispatcher("category_modify.jsp").forward(request,response);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
